import axios from 'axios'

// 创建 axios 实例
const apiClient = axios.create({
  baseURL: 'http://localhost/api'
})

// 添加请求拦截器
apiClient.interceptors.request.use(
  config => {
    // 对于登录和注册请求，不添加 Token
    if (!config.url.includes('/user/login') && !config.url.includes('/user/register')) {
      const token = localStorage.getItem('token')
      if (token) {
        config.headers.Token = token
      }
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

export default apiClient
